Skip to main content
Version: 1.0.16

ALTER PROCEDURE

ALTER PROCEDURE — Change the Definition of a Procedure

Synopsis

ALTER PROCEDURE name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]

action [ ... ] [ RESTRICT ]

ALTER PROCEDURE name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]

RENAME TO new_name

ALTER PROCEDURE name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]

OWNER TO { new_owner | CURRENT_USER | SESSION_USER }

ALTER PROCEDURE name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]

SET SCHEMA new_schema

ALTER PROCEDURE name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ]

DEPENDS ON EXTENSION extension_name

where action is one of:

[ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER

SET configuration_parameter { TO | = } { value | DEFAULT }

SET configuration_parameter FROM CURRENT

RESET configuration_parameter

RESET ALL

Description

ALTER PROCEDURE changes the definition of a procedure.

To use ALTER PROCEDURE, you must own the procedure. To change the schema of a procedure, you must also have CREATE privilege on the new schema. To change the owner, you must also be a direct or indirect member of the new owning role, and that role must have CREATE privilege on the procedure's schema (these restrictions enforce that changing the owner cannot do anything you couldn't do by dropping and recreating the procedure. However, a superuser can always change ownership of any procedure).

Parameters

name

The name (optionally schema-qualified) of an existing procedure. If no argument list is specified, the name must be unique in its schema.

argmode

The mode of an argument: IN or VARIADIC. If omitted, the default is IN.

argname

The name of an argument. Note that ALTER PROCEDURE does not actually care about argument names, since only the argument data types are needed to determine the procedure's identity.

argtype

The data type(s) of the procedure's arguments (if any), optionally schema-qualified.

new_name

The new name of the procedure.

new_owner

The new owner of the procedure. Note that if the procedure is marked as SECURITY DEFINER, it will subsequently be executed as the new owner.

new_schema

The new schema for the procedure.

extension_name

The name of the extension on which the procedure depends.

[ EXTERNAL ] SECURITY INVOKER

[ EXTERNAL ] SECURITY DEFINER

Changes whether the procedure is a security definer. The keyword EXTERNAL is ignored for SQL conformance. See CREATE PROCEDURE for more information about this capability.

configuration_parameter

value

Adds or changes an assignment to be made to a configuration parameter when the procedure is called. If value is DEFAULT, or the equivalent RESET is used, the procedure-local setting is removed, so the procedure will execute with the value present in its environment. Use RESET ALL to clear all procedure-local settings. SET FROM CURRENT saves the current value of the parameter when ALTER PROCEDURE is executed as the value to apply when entering the procedure.

RESTRICT — Ignored for SQL standard conformance.

Examples

# To rename the procedure insert_data with two integer arguments to insert_record:

ALTER PROCEDURE insert_data(integer, integer) RENAME TO insert_record;

# To change the owner of the procedure insert_data with two integer arguments to joe:

ALTER PROCEDURE insert_data(integer, integer) OWNER TO joe;

# To change the schema of the procedure insert_data with two integer arguments to accounting:

ALTER PROCEDURE insert_data(integer, integer) SET SCHEMA accounting;

# To mark the procedure insert_data(integer, integer) as dependent on extension myext:

ALTER PROCEDURE insert_data(integer, integer) DEPENDS ON EXTENSION myext;

# To adjust the automatic search path of a procedure:

ALTER PROCEDURE check_password(text) SET search_path = admin, pg_temp;

# To disable the automatic search_path setting for a procedure:

ALTER PROCEDURE check_password(text) RESET search_path;

# The procedure will now execute with whatever search path is used by its caller.

See Also

CREATE PROCEDURE, DROP PROCEDURE, ALTER FUNCTION, ALTER ROUTINE